using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace OsdmSoftware.CommonLibrary
{
    public partial class ColorEditor: UserControl
    {
        List<Color> colors = new List<Color>();

        public ColorEditor(string propertyLabel, Color value)
        {
            InitializeComponent();
            this.label1.Text = propertyLabel;

            comboBox1.Items.Add("Blue");
            colors.Add(Color.Blue);

            comboBox1.Items.Add("Green");
            colors.Add(Color.Green);

            comboBox1.Items.Add("Red");
            colors.Add(Color.Red);

            comboBox1.Items.Add("Yellow");
            colors.Add(Color.Yellow);

            comboBox1.Items.Add("White");
            colors.Add(Color.White);

            comboBox1.Items.Add("Orange");
            colors.Add(Color.Orange);

            comboBox1.Items.Add("Brown");
            colors.Add(Color.Brown);

            comboBox1.Items.Add("Gray");
            colors.Add(Color.Gray);

            comboBox1.Items.Add("SkyBlue");
            colors.Add(Color.SkyBlue);

            this.ColorEdit = value;
        }

        public Color ColorEdit
        {
            get
            {
                if (comboBox1.SelectedIndex == -1)
                    return Color.Black;
                else
                    return colors[comboBox1.SelectedIndex];
            }
            set
            {
                comboBox1.SelectedIndex = -1;
                for (int i = 0; i < colors.Count; i++)
                {
                    if (Utility.RGBEqual(colors[i], value))
                    {
                        comboBox1.SelectedIndex = i;
                        break;
                    }
                }
            }
        }
    }

    public class ColorPropEditor: BaseEditor, IPropertyEditor
    {
        public Control CreateEditor(PropertyEditors pe, string propertyName, string propertyLabel,
            Type propType, object obj, object value, Control parent, int top, out int height)
        {
            ColorEditor oe = new ColorEditor(propertyLabel, (Color) value);
            oe.Top = top;
            parent.Controls.Add(oe);
            height = 23;
            return oe;
        }

        public object GetValueFromEditor(Control editor, string propertyName, object obj, out bool OK)
        {
            OK = true;
            return ((ColorEditor) editor).ColorEdit;
        }

        public bool RequiresKeyboardInput()
        {
            return false;
        }

        public bool SupportsInherited()
        {
            return false;
        }
    }
}
